Page({
  data: {
    background:[
      "https://pic.baike.soso.com/pqpic/baikepic/20840/cut-20131101105126-1754793407.jpg/0",
      "https://ts1.cn.mm.bing.net/th/id/R-C.7d62ad8df77115f40e780d8f3415ad91?rik=3NbNeEzFolZdUg&riu=http%3a%2f%2fwww.hbxha.com%2fpic%2fother%2f2018-07-05-17-37-276.jpeg&ehk=6%2bf5V%2blUDEYWjJdqCE6MqwZSHYZOFe0OwYBWUfvumfw%3d&risl=&pid=ImgRaw&r=0",
      "https://pic.baike.soso.com/p/20131101/20131101105225-123604110.jpg"
    ],
    currentNews:{
        title:[],
    },
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    circular: true,
    interval: 2000,
    duration: 500,
    previousMargin: 0,
    nextMargin: 0
  },
  onLoad(option){
    let that = this;
    wx.request({
      url: "https://hongzhe.xyz/weixin",
      success: function (res) {

          let titles = []
          let contents = []
          for (let key in res.data) {
              titles.push(key)
              contents.push(res.data[key])
          }
          that.setData({
              currentNews: {
                  title:titles,
                  desc: contents,
              }
          })
      }
  })


  },
  changeProperty: function (e) {
    console.log(e.detail.value)
    var propertyName = e.currentTarget.dataset.propertyName
    var newData = {}
    newData[propertyName] = e.detail.value
    this.setData(newData)
  },
  changeIndicatorDots: function (e) {
    this.setData({
      indicatorDots: !this.data.indicatorDots
    })
  },
  changeAutoplay: function (e) {
    this.setData({
      autoplay: !this.data.autoplay
    })
  },
  intervalChange: function (e) {
    this.setData({
      interval: e.detail.value
    })
  },
  durationChange: function (e) {
    this.setData({
      duration: e.detail.value
    })
  },
  upper(e) {
    console.log(e)
  },

  lower(e) {
    console.log(e)
  },

  scroll(e) {
    console.log(e)
  },

  scrollToTop() {
    this.setAction({
      scrollTop: 0
    })
  },
  news_handler:function(event){
    var message = this.data
    let index = parseInt(event.currentTarget.dataset.news)


    wx.navigateTo({
      url: '../news-details/news-details?id='+index.toString(),
      events: {
        // 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
        acceptDataFromOpenedPage: function(data) {
          console.log(data)
        },
        someEvent: function(data) {
          console.log(data)
        }

      },
      success: function(res) {
        // 通过eventChannel向被打开页面传送数据
        res.eventChannel.emit('acceptDataFromOpenerPage',message)
      }
    })
  }
})
